package com.amumu.drama.common.constant;

import com.google.common.collect.Maps;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.Map;

/**
 * @author sunzhuang
 * @date 2024/5/13 20:32
 * @slogan 天下风云出我辈, 一入代码岁月催
 * @desc  sku上下架
 */
@Getter
public enum SkuOnTypeEnum {
    FULU_RECHARGE(0,"下架"),
    MANUAL_RECHARGE(1,"上架");
    private Integer code;

    private String desc;

    private static Map<Integer, SkuOnTypeEnum> UNINDEX = Maps.uniqueIndex(Arrays.asList(values()), SkuOnTypeEnum::getCode);
    private static Map<String, SkuOnTypeEnum> UNINDEX_DESC = Maps.uniqueIndex(Arrays.asList(values()), SkuOnTypeEnum::getDesc);

    SkuOnTypeEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static SkuOnTypeEnum getByCode(Integer code){
        if (code==null){
            return null;
        }
        return UNINDEX.getOrDefault(code,null);
    }

    public static SkuOnTypeEnum getByDesc(String desc){
        if (StringUtils.isEmpty(desc)){
            return null;
        }
        return UNINDEX_DESC.getOrDefault(desc,null);
    }
}
